package com.piece.core.pay.enums;

import com.piece.core.framework.util.collection.ArrayUtil;
import com.piece.core.pay.client.PayClientConfig;
import com.piece.core.pay.client.impl.alipay.AliPayClientConfig;
import com.piece.core.pay.client.impl.wxpay.WXPayClientConfig;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 支付渠道的编码
 */
@Getter
@AllArgsConstructor
public enum PayChannelType {

    WX_PUB("wx_pub", "微信JSAPI支付", WXPayClientConfig.class), // 公众号网页
    WX_LITE("wx_lite", "微信小程序支付", WXPayClientConfig.class),
    WX_APP("wx_app", "微信App支付", WXPayClientConfig.class),
    WX_NATIVE("wx_native", "微信本地支付", WXPayClientConfig.class),


    ALIPAY_PC("alipay_pc", "支付宝PC网页支付", AliPayClientConfig.class),
    ALIPAY_WAP("alipay_wap", "支付宝Wap网页支付", AliPayClientConfig.class),
    ALIPAY_APP("alipay_app", "支付宝App支付", AliPayClientConfig.class),
    ALIPAY_QR("alipay_qr", "支付宝扫码支付", AliPayClientConfig.class);

    /**
     * 编码
     *
     * <p>
     *     参考 https://www.pingxx.com/api/支付渠道属性值.html
     * </p>
     */
    private final String code;
    /**
     * 名字
     */
    private final String name;

    /**
     * 配置类
     */
    private final Class<? extends PayClientConfig> configClass;

    /**
     * 微信支付
     */
    public static final String WECHAT = "WECHAT";

    /**
     * 支付宝支付
     */
    public static final String ALIPAY = "ALIPAY";

    public static PayChannelType getByCode(String code) {
        return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values());
    }
}
